package com.alibaba.citrus.cr.mn.order.center.facade.function.common;

import com.alibaba.citrus.cr.common.enums.ordercenter.ExchangeOrderTypeEnum;
import com.alibaba.citrus.cr.common.enums.ordercenter.ReturnOrderTypeEnum;
import com.alibaba.citrus.cr.common.enums.ordercenter.SalesOrderDeliveryMethodEnum;
import com.alibaba.citrus.cr.common.enums.ordercenter.SalesOrderTypeEnum;
import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.mnordercenter.model.dto.*;
import org.apache.commons.lang.StringUtils;

import java.util.Objects;

/**
 * @author zhangxiaorui
 * @ClassName AbstractOrderBizCreateService
 * @description: TODO
 * @date 2023/05/16 14:07
 * @version: 1.0
 */
public abstract class AbstractOrderBizCreateService {

    private static final Log log = Log.getLogger(AbstractOrderBizCreateService.class);

    public void assembleSalesOrderCreateCommonInfo(SalesOrderBizBatchCreateRequest bizOrderCreateList) {
        for (SalesOrderBizCreateRequest bizCreateRequest : bizOrderCreateList.getOrderList()) {

            String salesOrderType = bizCreateRequest.getSalesOrderType();
            if (StringUtils.isNotBlank(salesOrderType)) {
                SalesOrderTypeEnum salesOrderTypeEnum = SalesOrderTypeEnum.of(salesOrderType);
                if (Objects.nonNull(salesOrderTypeEnum)) {
                    bizCreateRequest.setSalesOrderTypeName(salesOrderTypeEnum.getDesc());
                }
            }

            String deliveryMethodCode = bizCreateRequest.getDeliveryMethodCode();
            if (StringUtils.isNotBlank(deliveryMethodCode)) {
                SalesOrderDeliveryMethodEnum deliveryMethodEnum = SalesOrderDeliveryMethodEnum.of(deliveryMethodCode);
                if (Objects.nonNull(deliveryMethodEnum)) {
                    bizCreateRequest.setDeliveryMethodName(deliveryMethodEnum.getDesc());
                }
            }
        }
    }


    public void assembleReturnOrderCreateCommonInfo(ReturnOrderBizBatchCreateRequest bizOrderCreateList) {
        for (ReturnOrderBizCreateRequest bizCreateRequest : bizOrderCreateList.getOrderList()) {

            String salesOrderType = bizCreateRequest.getSalesOrderType();
            if (StringUtils.isNotBlank(salesOrderType)) {
                ReturnOrderTypeEnum returnOrderTypeEnum = ReturnOrderTypeEnum.of(salesOrderType);
                if (Objects.nonNull(returnOrderTypeEnum)) {
                    bizCreateRequest.setSalesOrderTypeName(returnOrderTypeEnum.getDesc());
                }
            }

            String deliveryMethodCode = bizCreateRequest.getDeliveryMethodCode();
            if (StringUtils.isNotBlank(deliveryMethodCode)) {
                SalesOrderDeliveryMethodEnum deliveryMethodEnum = SalesOrderDeliveryMethodEnum.of(deliveryMethodCode);
                if (Objects.nonNull(deliveryMethodEnum)) {
                    bizCreateRequest.setDeliveryMethodName(deliveryMethodEnum.getDesc());
                }
            }
        }
    }

    public void assembleExchangeOrderCreateCommonInfo(ExchangeOrderBizBatchCreateRequest bizOrderCreateList) {
        for (ExchangeOrderBizCreateRequest bizCreateRequest : bizOrderCreateList.getOrderList()) {

            String salesOrderType = bizCreateRequest.getSalesOrderType();
            if (StringUtils.isNotBlank(salesOrderType)) {
                ExchangeOrderTypeEnum exchangeOrderTypeEnum = ExchangeOrderTypeEnum.of(salesOrderType);
                if (Objects.nonNull(exchangeOrderTypeEnum)) {
                    bizCreateRequest.setSalesOrderTypeName(exchangeOrderTypeEnum.getDesc());
                }
            }

            String deliveryMethodCode = bizCreateRequest.getDeliveryMethodCode();
            if (StringUtils.isNotBlank(deliveryMethodCode)) {
                SalesOrderDeliveryMethodEnum deliveryMethodEnum = SalesOrderDeliveryMethodEnum.of(deliveryMethodCode);
                if (Objects.nonNull(deliveryMethodEnum)) {
                    bizCreateRequest.setDeliveryMethodName(deliveryMethodEnum.getDesc());
                }
            }
        }
    }
}
